<?php

namespace App\Console\Commands;

use App\Models\User;
use Illuminate\Console\Command;
use Illuminate\Support\Benchmark;
use Illuminate\Support\Carbon;
use Illuminate\Support\Collection;
use Illuminate\Support\Lottery;
use Illuminate\Support\Number;
use Illuminate\Support\Str;

class Collections extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'test';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Execute the console command.
     */
    public function handle()
    {
        $collection = collect([1, 2, 3]);
        
        $collection->unless(true, function (Collection $collection) {
            return $collection->push(4);
        });
        
        $collection->unless(false, function (Collection $collection) {
            return $collection->push(5);
        });
        
        var_dump($collection->all());
 
        // [1, 2, 3, 5]
        // echo Number::currency(100, 'CNY', 'zh_CN');
        // echo Number::fileSize(1024, 2);
        // Benchmark::dd(fn () => User::find(1), 10); // 0.1 ms 会终止掉后面的执行
        // echo now()->toString();
        // defer(function () {
        //     sleep(1);
        //     echo 'Hello World';
        // });
        Lottery::odds(10, 20)// 10/20的概率赢
    ->winner(function (){echo 'winner';})
    ->loser(function (){echo 'lost';})
    ->choose();
    // usleep(5000000);echo 'dd';
    $ulib = Str::ulid();
    var_dump($ulib);
    echo Carbon::createFromId($ulib);
    }   
}
